﻿using System;
using System.Collections.Generic;
using Helpers;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.CampaignBehaviors;
using TaleWorlds.CampaignSystem.CharacterDevelopment;
using TaleWorlds.CampaignSystem.Conversation;
using TaleWorlds.CampaignSystem.CraftingSystem;
using TaleWorlds.CampaignSystem.Extensions;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem.Issues
{
	// Token: 0x02000305 RID: 773
	public class GangLeaderNeedsSpecialWeaponsIssueBehavior : CampaignBehaviorBase
	{
		// Token: 0x06002D0D RID: 11533 RVA: 0x000BCC9F File Offset: 0x000BAE9F
		public override void RegisterEvents()
		{
			CampaignEvents.OnCheckForIssueEvent.AddNonSerializedListener(this, new Action<Hero>(this.OnCheckForIssue));
		}

		// Token: 0x06002D0E RID: 11534 RVA: 0x000BCCB8 File Offset: 0x000BAEB8
		private void OnCheckForIssue(Hero hero)
		{
			Campaign.Current.IssueManager.AddPotentialIssueData(hero, this.ConditionsHold(hero) ? new PotentialIssueData(new PotentialIssueData.StartIssueDelegate(this.OnStartIssue), typeof(GangLeaderNeedsSpecialWeaponsIssueBehavior.GangLeaderNeedsSpecialWeaponsIssue), IssueBase.IssueFrequency.VeryCommon, null) : new PotentialIssueData(typeof(GangLeaderNeedsSpecialWeaponsIssueBehavior.GangLeaderNeedsSpecialWeaponsIssue), IssueBase.IssueFrequency.VeryCommon));
		}

		// Token: 0x06002D0F RID: 11535 RVA: 0x000BCD0D File Offset: 0x000BAF0D
		private bool ConditionsHold(Hero issueGiver)
		{
			return issueGiver.CurrentSettlement != null && issueGiver.IsGangLeader && issueGiver.CurrentSettlement.IsTown && Campaign.Current.GetCampaignBehavior<ICraftingCampaignBehavior>() != null;
		}

		// Token: 0x06002D10 RID: 11536 RVA: 0x000BCD3B File Offset: 0x000BAF3B
		private IssueBase OnStartIssue(in PotentialIssueData pid, Hero issueOwner)
		{
			return new GangLeaderNeedsSpecialWeaponsIssueBehavior.GangLeaderNeedsSpecialWeaponsIssue(issueOwner);
		}

		// Token: 0x06002D11 RID: 11537 RVA: 0x000BCD43 File Offset: 0x000BAF43
		public override void SyncData(IDataStore dataStore)
		{
		}

		// Token: 0x04000D80 RID: 3456
		private const IssueBase.IssueFrequency SpecialWeaponOrderIssueFrequency = IssueBase.IssueFrequency.VeryCommon;

		// Token: 0x0200061F RID: 1567
		public class GangLeaderNeedsSpecialWeaponsIssue : IssueBase
		{
			// Token: 0x06004B38 RID: 19256 RVA: 0x0015ABB6 File Offset: 0x00158DB6
			internal static void AutoGeneratedStaticCollectObjectsGangLeaderNeedsSpecialWeaponsIssue(object o, List<object> collectedObjects)
			{
				((GangLeaderNeedsSpecialWeaponsIssueBehavior.GangLeaderNeedsSpecialWeaponsIssue)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x06004B39 RID: 19257 RVA: 0x0015ABC4 File Offset: 0x00158DC4
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x17000F2B RID: 3883
			// (get) Token: 0x06004B3A RID: 19258 RVA: 0x0015ABCD File Offset: 0x00158DCD
			public int NumberOfDaggersRequested
			{
				get
				{
					return 2 + MathF.Ceiling(4f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x17000F2C RID: 3884
			// (get) Token: 0x06004B3B RID: 19259 RVA: 0x0015ABE2 File Offset: 0x00158DE2
			public int BaseGoldRewardPerDagger
			{
				get
				{
					return 200 + MathF.Ceiling(500f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x17000F2D RID: 3885
			// (get) Token: 0x06004B3C RID: 19260 RVA: 0x0015ABFB File Offset: 0x00158DFB
			public override bool IsThereAlternativeSolution
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17000F2E RID: 3886
			// (get) Token: 0x06004B3D RID: 19261 RVA: 0x0015ABFE File Offset: 0x00158DFE
			public override bool IsThereLordSolution
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17000F2F RID: 3887
			// (get) Token: 0x06004B3E RID: 19262 RVA: 0x0015AC01 File Offset: 0x00158E01
			protected override bool IssueQuestCanBeDuplicated
			{
				get
				{
					return false;
				}
			}

			// Token: 0x06004B3F RID: 19263 RVA: 0x0015AC04 File Offset: 0x00158E04
			public GangLeaderNeedsSpecialWeaponsIssue(Hero issueOwner) : base(issueOwner, CampaignTime.DaysFromNow(30f))
			{
			}

			// Token: 0x17000F30 RID: 3888
			// (get) Token: 0x06004B40 RID: 19264 RVA: 0x0015AC17 File Offset: 0x00158E17
			public override TextObject IssueBriefByIssueGiver
			{
				get
				{
					return new TextObject("{=fmjWsUB6}Yeah... I've heard about your skills as a crafter of weapons. Now, nothing inspires my lads to shed my enemies' blood than the feel of a really well-made blade in their hands. Could you make me some? I'll pay well.", null);
				}
			}

			// Token: 0x17000F31 RID: 3889
			// (get) Token: 0x06004B41 RID: 19265 RVA: 0x0015AC24 File Offset: 0x00158E24
			public override TextObject IssueAcceptByPlayer
			{
				get
				{
					return new TextObject("{=UdnXHLSh}What do you want exactly?", null);
				}
			}

			// Token: 0x17000F32 RID: 3890
			// (get) Token: 0x06004B42 RID: 19266 RVA: 0x0015AC34 File Offset: 0x00158E34
			public override TextObject IssueQuestSolutionExplanationByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=xmETCOam}Daggers. Good, sharp, light daggers that they can hide under their clothes, so the guards won't stop them. We want to order {REQUESTED_AMOUNT} daggers and I guarantee a minimum of {REWARD_PER_DAGGER} denars for each, more if they're of exceptional quality. Also I can arrange things with the smith of {QUEST_SETTLEMENT} for you to work in his workshop.", null);
					textObject.SetTextVariable("REQUESTED_AMOUNT", this.NumberOfDaggersRequested);
					textObject.SetTextVariable("REWARD_PER_DAGGER", this.BaseGoldRewardPerDagger);
					textObject.SetTextVariable("QUEST_SETTLEMENT", base.IssueOwner.CurrentSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x17000F33 RID: 3891
			// (get) Token: 0x06004B43 RID: 19267 RVA: 0x0015AC8C File Offset: 0x00158E8C
			public override TextObject IssueQuestSolutionAcceptByPlayer
			{
				get
				{
					return new TextObject("{=goLdeLsT}Alright I will forge your daggers.", null);
				}
			}

			// Token: 0x17000F34 RID: 3892
			// (get) Token: 0x06004B44 RID: 19268 RVA: 0x0015AC99 File Offset: 0x00158E99
			public override TextObject Title
			{
				get
				{
					return new TextObject("{=tm9PiOMA}Special Weapon Order", null);
				}
			}

			// Token: 0x17000F35 RID: 3893
			// (get) Token: 0x06004B45 RID: 19269 RVA: 0x0015ACA6 File Offset: 0x00158EA6
			public override TextObject Description
			{
				get
				{
					TextObject textObject = new TextObject("{=auIV2JoK}{ISSUE_GIVER.LINK} is looking for someone to craft special weapons for {?ISSUE_GIVER.GENDER}her{?}his{\\?} men.", null);
					textObject.SetCharacterProperties("ISSUE_GIVER", base.IssueOwner.CharacterObject, false);
					return textObject;
				}
			}

			// Token: 0x06004B46 RID: 19270 RVA: 0x0015ACCA File Offset: 0x00158ECA
			public override IssueBase.IssueFrequency GetFrequency()
			{
				return IssueBase.IssueFrequency.VeryCommon;
			}

			// Token: 0x06004B47 RID: 19271 RVA: 0x0015ACD0 File Offset: 0x00158ED0
			protected override bool CanPlayerTakeQuestConditions(Hero issueGiver, out IssueBase.PreconditionFlags flag, out Hero relationHero, out SkillObject skill)
			{
				flag = IssueBase.PreconditionFlags.None;
				relationHero = issueGiver;
				skill = DefaultSkills.Crafting;
				if (issueGiver.GetRelationWithPlayer() < -10f)
				{
					flag |= IssueBase.PreconditionFlags.Relation;
				}
				if (FactionManager.IsAtWarAgainstFaction(issueGiver.MapFaction, Hero.MainHero.MapFaction))
				{
					flag |= IssueBase.PreconditionFlags.AtWar;
				}
				if (Hero.MainHero.GetSkillValue(skill) < 30)
				{
					flag |= IssueBase.PreconditionFlags.Skill;
				}
				return flag == IssueBase.PreconditionFlags.None;
			}

			// Token: 0x06004B48 RID: 19272 RVA: 0x0015AD38 File Offset: 0x00158F38
			protected override float GetIssueEffectAmountInternal(IssueEffect issueEffect)
			{
				if (issueEffect == DefaultIssueEffects.IssueOwnerPower)
				{
					return -0.1f;
				}
				if (issueEffect == DefaultIssueEffects.SettlementSecurity)
				{
					return 0.5f;
				}
				return 0f;
			}

			// Token: 0x06004B49 RID: 19273 RVA: 0x0015AD5B File Offset: 0x00158F5B
			public override bool IssueStayAliveConditions()
			{
				return true;
			}

			// Token: 0x06004B4A RID: 19274 RVA: 0x0015AD5E File Offset: 0x00158F5E
			protected override void CompleteIssueWithTimedOutConsequences()
			{
			}

			// Token: 0x06004B4B RID: 19275 RVA: 0x0015AD60 File Offset: 0x00158F60
			protected override void OnGameLoad()
			{
			}

			// Token: 0x06004B4C RID: 19276 RVA: 0x0015AD62 File Offset: 0x00158F62
			protected override QuestBase GenerateIssueQuest(string questId)
			{
				return new GangLeaderNeedsSpecialWeaponsIssueBehavior.GangLeaderNeedsSpecialWeaponsIssueQuest(questId, base.IssueOwner, this.NumberOfDaggersRequested, this.BaseGoldRewardPerDagger, CampaignTime.DaysFromNow(30f), this.RewardGold);
			}

			// Token: 0x06004B4D RID: 19277 RVA: 0x0015AD8C File Offset: 0x00158F8C
			protected override void HourlyTick()
			{
			}

			// Token: 0x0400197D RID: 6525
			private const int IssueAndQuestDuration = 30;
		}

		// Token: 0x02000620 RID: 1568
		public class GangLeaderNeedsSpecialWeaponsIssueQuest : QuestBase
		{
			// Token: 0x06004B4E RID: 19278 RVA: 0x0015AD8E File Offset: 0x00158F8E
			internal static void AutoGeneratedStaticCollectObjectsGangLeaderNeedsSpecialWeaponsIssueQuest(object o, List<object> collectedObjects)
			{
				((GangLeaderNeedsSpecialWeaponsIssueBehavior.GangLeaderNeedsSpecialWeaponsIssueQuest)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x06004B4F RID: 19279 RVA: 0x0015AD9C File Offset: 0x00158F9C
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._currentCraftingOrder);
				collectedObjects.Add(this._playerAcceptedQuestLog);
				collectedObjects.Add(this._playerHasNeededItemsLog);
			}

			// Token: 0x06004B50 RID: 19280 RVA: 0x0015ADC9 File Offset: 0x00158FC9
			internal static object AutoGeneratedGetMemberValue_numberOfDaggersRequested(object o)
			{
				return ((GangLeaderNeedsSpecialWeaponsIssueBehavior.GangLeaderNeedsSpecialWeaponsIssueQuest)o)._numberOfDaggersRequested;
			}

			// Token: 0x06004B51 RID: 19281 RVA: 0x0015ADDB File Offset: 0x00158FDB
			internal static object AutoGeneratedGetMemberValue_baseGoldRewardPerDagger(object o)
			{
				return ((GangLeaderNeedsSpecialWeaponsIssueBehavior.GangLeaderNeedsSpecialWeaponsIssueQuest)o)._baseGoldRewardPerDagger;
			}

			// Token: 0x06004B52 RID: 19282 RVA: 0x0015ADED File Offset: 0x00158FED
			internal static object AutoGeneratedGetMemberValue_currentCraftingOrder(object o)
			{
				return ((GangLeaderNeedsSpecialWeaponsIssueBehavior.GangLeaderNeedsSpecialWeaponsIssueQuest)o)._currentCraftingOrder;
			}

			// Token: 0x06004B53 RID: 19283 RVA: 0x0015ADFA File Offset: 0x00158FFA
			internal static object AutoGeneratedGetMemberValue_completedCraftingOrders(object o)
			{
				return ((GangLeaderNeedsSpecialWeaponsIssueBehavior.GangLeaderNeedsSpecialWeaponsIssueQuest)o)._completedCraftingOrders;
			}

			// Token: 0x06004B54 RID: 19284 RVA: 0x0015AE0C File Offset: 0x0015900C
			internal static object AutoGeneratedGetMemberValue_playerAcceptedQuestLog(object o)
			{
				return ((GangLeaderNeedsSpecialWeaponsIssueBehavior.GangLeaderNeedsSpecialWeaponsIssueQuest)o)._playerAcceptedQuestLog;
			}

			// Token: 0x06004B55 RID: 19285 RVA: 0x0015AE19 File Offset: 0x00159019
			internal static object AutoGeneratedGetMemberValue_playerHasNeededItemsLog(object o)
			{
				return ((GangLeaderNeedsSpecialWeaponsIssueBehavior.GangLeaderNeedsSpecialWeaponsIssueQuest)o)._playerHasNeededItemsLog;
			}

			// Token: 0x17000F36 RID: 3894
			// (get) Token: 0x06004B56 RID: 19286 RVA: 0x0015AE26 File Offset: 0x00159026
			public override bool IsRemainingTimeHidden
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17000F37 RID: 3895
			// (get) Token: 0x06004B57 RID: 19287 RVA: 0x0015AE2C File Offset: 0x0015902C
			private TextObject QuestStartedLog
			{
				get
				{
					TextObject textObject = new TextObject("{=zo1shYCL}{QUEST_GIVER.LINK} told you that {?QUEST_GIVER.GENDER}her{?}his{\\?} men need a special dagger that should be light and small enough to hide from the city guards. {?QUEST_GIVER.GENDER}She{?}He{\\?} asked you to forge {REQUESTED_AMOUNT} daggers at the smith of {QUEST_SETTLEMENT}. {?QUEST_GIVER.GENDER}She{?}He{\\?} guaranteed to pay at least {REWARD_PER_ITEM} denars for each dagger and he is ready to pay extra depending on the quality of the weapons.", null);
					textObject.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, false);
					textObject.SetTextVariable("REQUESTED_AMOUNT", this._numberOfDaggersRequested);
					textObject.SetTextVariable("REWARD_PER_ITEM", this._baseGoldRewardPerDagger);
					textObject.SetTextVariable("QUEST_SETTLEMENT", base.QuestGiver.CurrentSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x17000F38 RID: 3896
			// (get) Token: 0x06004B58 RID: 19288 RVA: 0x0015AE9B File Offset: 0x0015909B
			private TextObject QuestSuccessLog
			{
				get
				{
					TextObject textObject = new TextObject("{=3uvbVxfx}You have delivered the weapons to {QUEST_GIVER.LINK} as promised.", null);
					textObject.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, false);
					return textObject;
				}
			}

			// Token: 0x17000F39 RID: 3897
			// (get) Token: 0x06004B59 RID: 19289 RVA: 0x0015AEC0 File Offset: 0x001590C0
			private TextObject QuestCanceledWarDeclaredLog
			{
				get
				{
					TextObject textObject = new TextObject("{=vW6kBki9}Your clan is now at war with {QUEST_GIVER.LINK}'s realm. Your agreement with {QUEST_GIVER.LINK} is canceled.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000F3A RID: 3898
			// (get) Token: 0x06004B5A RID: 19290 RVA: 0x0015AEF4 File Offset: 0x001590F4
			private TextObject QuestFailedLog
			{
				get
				{
					TextObject textObject = new TextObject("{=iTgVn26a}You have failed to bring the weapons to {QUEST_GIVER.LINK} in time.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000F3B RID: 3899
			// (get) Token: 0x06004B5B RID: 19291 RVA: 0x0015AF26 File Offset: 0x00159126
			public override TextObject Title
			{
				get
				{
					return new TextObject("{=tm9PiOMA}Special Weapon Order", null);
				}
			}

			// Token: 0x17000F3C RID: 3900
			// (get) Token: 0x06004B5C RID: 19292 RVA: 0x0015AF33 File Offset: 0x00159133
			private TextObject PlayerHasNeededItemsLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=kHio2hlU}You now have enough daggers to complete the quest. Return to {QUEST_GIVER.LINK} to hand them over.", null);
					textObject.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, false);
					return textObject;
				}
			}

			// Token: 0x06004B5D RID: 19293 RVA: 0x0015AF57 File Offset: 0x00159157
			public GangLeaderNeedsSpecialWeaponsIssueQuest(string questId, Hero questGiver, int numberOfDaggersRequested, int baseGoldRewardPerDagger, CampaignTime duration, int rewardGold) : base(questId, questGiver, duration, rewardGold)
			{
				this._numberOfDaggersRequested = numberOfDaggersRequested;
				this._baseGoldRewardPerDagger = baseGoldRewardPerDagger;
				this._craftingBehavior = Campaign.Current.GetCampaignBehavior<ICraftingCampaignBehavior>();
				this.SetDialogs();
				base.InitializeQuestOnCreation();
			}

			// Token: 0x06004B5E RID: 19294 RVA: 0x0015AF90 File Offset: 0x00159190
			protected override void SetDialogs()
			{
				TextObject npcText = new TextObject("{=siofh72D}Thank you, my friend. I'm looking forward to giving my boys their new toys.", null);
				TextObject npcText2 = new TextObject("{=cJOGUpSS}Any news about my orders?", null);
				TextObject text = new TextObject("{=R9NDaOhb}The daggers are almost ready. They just need a little more work...", null);
				TextObject npcText3 = new TextObject("{=CDXUehf0}Good, good.", null);
				TextObject text2 = new TextObject("{=wErSpkjy}I'm still working on it.", null);
				TextObject npcText4 = new TextObject("{=r2g61BjX}Well, my lads are anxiously waiting...", null);
				TextObject text3 = new TextObject("{=TBuyyh2S}There you go, that should be enough daggers for your men.", null);
				TextObject npcText5 = new TextObject("{=QCzB8DDX}Ah excellent, these will come in handy.", null);
				this.OfferDialogFlow = DialogFlow.CreateDialogFlow("issue_classic_quest_start", 100).NpcLine(npcText, null, null).Condition(() => Hero.OneToOneConversationHero == base.QuestGiver).Consequence(new ConversationSentence.OnConsequenceDelegate(this.QuestAcceptedConsequences)).CloseDialog();
				this.DiscussDialogFlow = DialogFlow.CreateDialogFlow("quest_discuss", 100).NpcLine(npcText2, null, null).Condition(() => Hero.OneToOneConversationHero == base.QuestGiver).BeginPlayerOptions().PlayerOption(text, null).NpcLine(npcText3, null, null).CloseDialog().PlayerOption(text2, null).NpcLine(npcText4, null, null).CloseDialog().PlayerOption(text3, null).ClickableCondition(new ConversationSentence.OnClickableConditionDelegate(this.CheckPlayerHasCompletedEnoughOrdersClickableCondition)).NpcLine(npcText5, null, null).Consequence(new ConversationSentence.OnConsequenceDelegate(this.SucceedQuest)).CloseDialog().EndPlayerOptions().CloseDialog();
			}

			// Token: 0x06004B5F RID: 19295 RVA: 0x0015B0DE File Offset: 0x001592DE
			private bool CheckPlayerHasCompletedEnoughOrdersClickableCondition(out TextObject explanation)
			{
				if (this._completedCraftingOrders >= this._numberOfDaggersRequested)
				{
					explanation = TextObject.Empty;
					return true;
				}
				explanation = new TextObject("{=mAvJcyY1}You haven't completed enough crafting orders yet.", null);
				return false;
			}

			// Token: 0x06004B60 RID: 19296 RVA: 0x0015B105 File Offset: 0x00159305
			private void QuestAcceptedConsequences()
			{
				base.StartQuest();
				this._currentCraftingOrder = this.GetDaggerCraftingOrder();
				this._playerAcceptedQuestLog = base.AddDiscreteLog(this.QuestStartedLog, new TextObject("{=scjHmuyF}Complete Crafting Orders", null), this._completedCraftingOrders, this._numberOfDaggersRequested, null, false);
			}

			// Token: 0x06004B61 RID: 19297 RVA: 0x0015B144 File Offset: 0x00159344
			private void CheckIfPlayerReadyToReturnItems()
			{
				if (this._playerHasNeededItemsLog == null && this._playerAcceptedQuestLog.CurrentProgress >= this._numberOfDaggersRequested)
				{
					this._playerHasNeededItemsLog = base.AddLog(this.PlayerHasNeededItemsLogText, false);
					return;
				}
				if (this._playerHasNeededItemsLog != null && this._playerAcceptedQuestLog.CurrentProgress < this._numberOfDaggersRequested)
				{
					base.RemoveLog(this._playerHasNeededItemsLog);
					this._playerHasNeededItemsLog = null;
				}
			}

			// Token: 0x06004B62 RID: 19298 RVA: 0x0015B1AE File Offset: 0x001593AE
			protected override void OnTimedOut()
			{
				if (this._playerHasNeededItemsLog != null && this._playerHasNeededItemsLog.CurrentProgress >= this._numberOfDaggersRequested)
				{
					this.SucceedQuest();
					return;
				}
				this.FailQuest();
			}

			// Token: 0x06004B63 RID: 19299 RVA: 0x0015B1D8 File Offset: 0x001593D8
			private void SucceedQuest()
			{
				base.AddLog(this.QuestSuccessLog, false);
				TraitLevelingHelper.OnIssueFailed(Hero.MainHero, new Tuple<TraitObject, int>[]
				{
					new Tuple<TraitObject, int>(DefaultTraits.Honor, 30)
				});
				this.RelationshipChangeWithQuestGiver = 5;
				base.QuestGiver.AddPower(10f);
				if (this._currentCraftingOrder != null)
				{
					this._craftingBehavior.CancelCustomOrder(base.QuestGiver.CurrentSettlement.Town, this._currentCraftingOrder);
				}
				GiveGoldAction.ApplyForQuestBetweenCharacters(base.QuestGiver, Hero.MainHero, this._baseGoldRewardPerDagger * this._completedCraftingOrders, false);
				base.CompleteQuestWithSuccess();
			}

			// Token: 0x06004B64 RID: 19300 RVA: 0x0015B278 File Offset: 0x00159478
			private void FailQuest()
			{
				this.RelationshipChangeWithQuestGiver = -5;
				base.QuestGiver.AddPower(-10f);
				this._craftingBehavior.CancelCustomOrder(base.QuestGiver.CurrentSettlement.Town, this._currentCraftingOrder);
				base.CompleteQuestWithFail(this.QuestFailedLog);
			}

			// Token: 0x06004B65 RID: 19301 RVA: 0x0015B2CA File Offset: 0x001594CA
			protected override void RegisterEvents()
			{
				CampaignEvents.WarDeclared.AddNonSerializedListener(this, new Action<IFaction, IFaction, DeclareWarAction.DeclareWarDetail>(this.OnWarDeclared));
				CampaignEvents.OnCraftingOrderCompletedEvent.AddNonSerializedListener(this, new Action<Town, CraftingOrder, ItemObject, Hero>(this.OnCraftingOrderCompleted));
			}

			// Token: 0x06004B66 RID: 19302 RVA: 0x0015B2FC File Offset: 0x001594FC
			private void OnCraftingOrderCompleted(Town town, CraftingOrder craftingOrder, ItemObject craftedItem, Hero completerHero)
			{
				if (craftingOrder == this._currentCraftingOrder)
				{
					this._completedCraftingOrders++;
					if (this._completedCraftingOrders == this._numberOfDaggersRequested)
					{
						TextObject textObject = new TextObject("{=T4q1DkfF}You have completed {QUEST_GIVER.NAME}'s request, you can go back to receive your reward or keep working on more orders.", null);
						textObject.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, false);
						MBInformationManager.AddQuickInformation(textObject, 0, null, "");
					}
					if (this._completedCraftingOrders < 10)
					{
						this._playerAcceptedQuestLog.UpdateCurrentProgress(this._completedCraftingOrders);
						this.CheckIfPlayerReadyToReturnItems();
						this._currentCraftingOrder = this.GetDaggerCraftingOrder();
						return;
					}
					if (this._completedCraftingOrders == 10)
					{
						this._currentCraftingOrder = null;
						TextObject textObject2 = new TextObject("{=1WbsW7I7}{QUEST_GIVER.NAME} won’t need anymore daggers. You can go back to {?QUEST_GIVER.GENDER}her{?}him{\\?} to get your reward.", null);
						textObject2.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, false);
						MBInformationManager.AddQuickInformation(textObject2, 0, null, "");
					}
				}
			}

			// Token: 0x06004B67 RID: 19303 RVA: 0x0015B3CC File Offset: 0x001595CC
			private CraftingOrder GetDaggerCraftingOrder()
			{
				CraftingTemplate randomElementWithPredicate = CraftingTemplate.All.GetRandomElementWithPredicate((CraftingTemplate x) => x.TemplateName.ToString() == "Dagger");
				CraftingOrder craftingOrder = this._craftingBehavior.CreateCustomOrderForHero(base.QuestGiver, this.GetCraftingDifficulty(), null, randomElementWithPredicate);
				base.AddTrackedObject(craftingOrder);
				return craftingOrder;
			}

			// Token: 0x06004B68 RID: 19304 RVA: 0x0015B425 File Offset: 0x00159625
			private float GetCraftingDifficulty()
			{
				return MathF.Clamp((float)MathF.Min(Hero.MainHero.GetSkillValue(DefaultSkills.Crafting), 100), 10f, 100f) + (float)MBRandom.RandomInt(-10, 10);
			}

			// Token: 0x06004B69 RID: 19305 RVA: 0x0015B458 File Offset: 0x00159658
			private void OnWarDeclared(IFaction faction1, IFaction faction2, DeclareWarAction.DeclareWarDetail declareWarDetail)
			{
				QuestHelper.CheckWarDeclarationAndFailOrCancelTheQuest(this, faction1, faction2, declareWarDetail, this.QuestCanceledWarDeclaredLog, this.QuestCanceledWarDeclaredLog, false);
			}

			// Token: 0x06004B6A RID: 19306 RVA: 0x0015B470 File Offset: 0x00159670
			protected override void InitializeQuestOnGameLoad()
			{
				this.SetDialogs();
				this._craftingBehavior = Campaign.Current.GetCampaignBehavior<ICraftingCampaignBehavior>();
				if (this._craftingBehavior == null)
				{
					base.CompleteQuestWithCancel(null);
				}
			}

			// Token: 0x06004B6B RID: 19307 RVA: 0x0015B497 File Offset: 0x00159697
			protected override void HourlyTick()
			{
			}

			// Token: 0x0400197E RID: 6526
			[SaveableField(1)]
			private readonly int _numberOfDaggersRequested;

			// Token: 0x0400197F RID: 6527
			[SaveableField(2)]
			private readonly int _baseGoldRewardPerDagger;

			// Token: 0x04001980 RID: 6528
			[SaveableField(3)]
			private CraftingOrder _currentCraftingOrder;

			// Token: 0x04001981 RID: 6529
			[SaveableField(4)]
			private int _completedCraftingOrders;

			// Token: 0x04001982 RID: 6530
			[SaveableField(5)]
			private JournalLog _playerAcceptedQuestLog;

			// Token: 0x04001983 RID: 6531
			[SaveableField(6)]
			private JournalLog _playerHasNeededItemsLog;

			// Token: 0x04001984 RID: 6532
			private const int SuccessRelationBonus = 5;

			// Token: 0x04001985 RID: 6533
			private const int SuccessPowerBonus = 10;

			// Token: 0x04001986 RID: 6534
			private const int FailRelationPenalty = -5;

			// Token: 0x04001987 RID: 6535
			private const int FailPowerPenalty = -10;

			// Token: 0x04001988 RID: 6536
			private const int MaxCraftingOrderDifficulty = 100;

			// Token: 0x04001989 RID: 6537
			private const int CraftingOrderDifficultyVariance = 10;

			// Token: 0x0400198A RID: 6538
			private const int MaxNumberOfCraftingOrdersAvailable = 10;

			// Token: 0x0400198B RID: 6539
			private const string DaggerCraftingTemplateId = "Dagger";

			// Token: 0x0400198C RID: 6540
			private ICraftingCampaignBehavior _craftingBehavior;
		}

		// Token: 0x02000621 RID: 1569
		public class GangLeaderNeedsSpecialWeaponsIssueTypeDefiner : SaveableTypeDefiner
		{
			// Token: 0x06004B6E RID: 19310 RVA: 0x0015B4B7 File Offset: 0x001596B7
			public GangLeaderNeedsSpecialWeaponsIssueTypeDefiner() : base(596061)
			{
			}

			// Token: 0x06004B6F RID: 19311 RVA: 0x0015B4C4 File Offset: 0x001596C4
			protected override void DefineClassTypes()
			{
				base.AddClassDefinition(typeof(GangLeaderNeedsSpecialWeaponsIssueBehavior.GangLeaderNeedsSpecialWeaponsIssue), 1, null);
				base.AddClassDefinition(typeof(GangLeaderNeedsSpecialWeaponsIssueBehavior.GangLeaderNeedsSpecialWeaponsIssueQuest), 2, null);
			}
		}
	}
}
